<template>
  <div>
    <el-dialog
      title="添加"
      width="85%"
      :visible.sync="show"
      @close="show = false"
    >
      <el-collapse v-model="activeNames">
        <el-collapse-item
          :title="comp.label"
          :name="index"
          v-for="(comp, index) in comps"
          :key="index"
        >
          <template slot="title" v-if="index">
            <div>{{ comp.label }}</div>
            <el-button @click.stop="importFile(index)">导入</el-button>
            <el-button @click.stop="() => {}">导出</el-button>
          </template>
          <component :is="comp.name" :data="data"></component>
        </el-collapse-item>
      </el-collapse>
      <template slow="footer">
        <div>
          <el-button
            v-for="btn in btns"
            :key="btn.label"
            :type="btn.type"
            size="mini"
            @click="() => btn.click()"
            >{{ btn.label }}</el-button
          >
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import BaseInfo from "./baseInfo.vue";
import Template from "./template.vue";
export default {
  name: "Dialog",
  componentName: "Dialog",
  props: ["data"],
  components: {
    BaseInfo,
    Template,
  },
  data() {
    return {
      activeNames: [0, 1],
      btns: [
        { label: "取消", click: this.cancel },
        { label: "保存", click: this.save, type: "primary" },
      ],
      show: false,
      comps: [
        { name: "BaseInfo", label: "基本信息" },
        { name: "Template", label: "模板" },
      ],
    };
  },
  methods: {
    showDialog() {
      this.show = true;
    },
    hideDialog() {
      this.show = false;
    },
    save() {
      console.log(this.data);
    },
    importFile() {
      this.data.template = [{ class: "demo班级", hobby: "养猫" }];
    },
  },
};
</script>

<style lang="scss" scoped></style>
